package testcase.app;
import common.Host;
import common.TestData;
import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import api.app.VerificationCodeForPassword;



/**
 * 帮忙医找回密码VerificationCodeForPassword接口测试用例
 * @author lipeng
 *
 */

public class TestVerificationCodeForPassword {
     /**
      * 帮忙医找回密码VerifiCationCodeForPassword接口测试环境数据驱动
      * @return
      * @throws Exception
      */
	  @DataProvider (name = "Test")
	  public static String[][] testRetrievePasswordDataProvider() throws Exception{
		  Host.setup("Test");
		  TestData td = new TestData("app/TestVerificationCodeForPassword.xml");
		  return td.getParam();
	  }
	  
	  /**
	   * 帮忙医找回密码VerificationcoDeforPassword接口
	   * @param casename   用例名称
	   * @param retrievepassword   找回密码
	   * @throws Exception
	   */
	  @Test (dataProvider = "Test" , groups = {"Test"})
	  public void testVerificationcodeforpasswordTestCase(String casename ,String retrievepassword)throws Exception{
		  //调用接口并将接口返回数据转换成json格式
		  
		  String result = VerificationCodeForPassword.post(retrievepassword);
		  JSONObject jsonResult;
		  if (result == null || result.isEmpty())
		  {
			  jsonResult = null;
		  }
		  else
		  {
			  jsonResult = new JSONObject(result);
		  }
		  
		  //设置检查点
		switch (casename) {
		case "userAccount":
			Assert.assertTrue(jsonResult.getJSONObject("Data").getBoolean("MobileExist"));
			break;
        case "shortUserAccount":
    	    Assert.assertFalse(jsonResult.getJSONObject("Data").getBoolean("MobileExist"));
			break;
        case "longUserAccount":
    	    Assert.assertFalse(jsonResult.getJSONObject("Data").getBoolean("MobileExist"));
			break;
        case "ErrorUserAccount":
        	Assert.assertFalse(jsonResult.getJSONObject("Data").getBoolean("MobileExist"));
			break;	
        case "NoUserAccount":
    	    Assert.assertTrue(result.isEmpty());
			break;
        default:
			Assert.fail();
			break;
		}
	  }
}
